$(function () {
  let form = layui.form
  let layer = layui.layer
  // 需求1:密码校验,新密码 旧密码 确认密码ad校验
  form.verify({
    pwd: [
      /^[\S]{6,15}$/
      , '密码必须6到15位，且不能出现空格'
    ],
    dif: function (value) {
      let oldpwd = $('form [name=oldPwd]').val()
      // console.log(pwd)
      if (value == oldpwd) {
        return '新密码和旧密码不能一致,请重新输入!'
      }
    },
    same: function (value) {
      let newpwd = $('form [name=newPwd]').val()
      if (value !== newpwd) {
        return '两次新密码输入不一致!'
      }

    }
  })

  // 需求2:修改密码
  $('#formPwd').on('submit', function (e) {
    e.preventDefault()
    axios({
      method: "POST",
      url: '/my/updatepwd',
      data: $(this).serialize()
    }).then(res => {
      if (res.data.status !== 0) {
        return layer.msg(res.data.message)
      }
      layer.msg('恭喜你!修改密码成功!')
      $('#formPwd')[0].reset()
      window.parent.location.href = '/login.html'
    })
  })

})